package com.huawei.appgallery.purchasehistory.ui.activity;

import android.app.ActionBar;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.huawei.appgallery.foundation.service.common.protocol.request.AppListFragmentRequest;
import com.huawei.appgallery.foundation.ui.framework.uikit.ContractFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.FixViewPager;
import com.huawei.appgallery.purchasehistory.api.AppTracesListFragmentProtocol;
import com.huawei.appgallery.purchasehistory.api.AppTracesListFragmentProtocol.Request;
import com.huawei.appgallery.purchasehistory.impl.PurchaseHistoryManager;
import com.huawei.appgallery.purchasehistory.ui.fragment.FamilyShareAppsFragment;
import com.huawei.appgallery.purchasehistory.ui.protocol.PurchaseHistoryProtocol;
import com.huawei.appgallery.purchasehistory.ui.widget.ToolBarIcon;
import huawei.widget.HwSubTabWidget;
import huawei.widget.HwSubTabWidget.a;
import huawei.widget.HwSubTabWidget.b;
import o.azb;
import o.azc;
import o.cgv;
import o.ciy;
import o.cjk;
import o.cjm;
import o.cjo;
import o.SomeFragmentStateAdapter;
import o.csp;
import o.cst;
import o.cst.d;
import o.cst.e;
import o.cst.f;
import o.cst.h;
import o.csv;
import o.cth;
import o.cti;
import o.ctj;
import o.ctm;
import o.ctn;
import o.cto;
import o.ctp;
import o.ContentManager;
import o.epv;
import o.evx;
import o.FragmentManager;
import o.FragmentTransaction;
import org.jetbrains.annotations.NotNull;

public class PurchaseFamilyShareAppsActivity extends PurchaseMenuActivity<PurchaseHistoryProtocol> implements cth, OnClickListener, cto, ctj, ctm, b {
    private String ʿ = "";
    private HwSubTabWidget ˈ;
    private ContractFragment ˊˊ;
    private ContractFragment ˊˋ;
    protected boolean ˊॱ = true;
    private int ˋˊ;
    protected ToolBarIcon ˋॱ;
    protected String ˏॱ = "";
    protected String ͺ = "";
    private String ॱˊ;

    class c extends SomeFragmentStateAdapter {
        Fragment ˎ;
        final /* synthetic */ PurchaseFamilyShareAppsActivity ॱ;

        c(PurchaseFamilyShareAppsActivity purchaseFamilyShareAppsActivity, FragmentManager juVar) {
            this.ॱ = purchaseFamilyShareAppsActivity;
            super(juVar);
        }

        @NotNull
        public Object instantiateItem(ViewGroup viewGroup, int i) {
            ContractFragment contractFragment = (ContractFragment) super.instantiateItem(viewGroup, i);
            if (i == 0) {
                this.ॱ.ˊˋ = contractFragment;
            } else if (i == 1) {
                this.ॱ.ˊˊ = contractFragment;
            }
            return contractFragment;
        }

        public Fragment getItem(int i) {
            cjo appTracesListFragmentProtocol = new AppTracesListFragmentProtocol();
            AppListFragmentRequest request;
            switch (i) {
                case 0:
                    request = new Request();
                    request.ॱ(0);
                    request.ʽ(false);
                    appTracesListFragmentProtocol.ˏ(request);
                    request.ॱˊ(this.ॱ.ॱˊ);
                    this.ॱ.ˊˋ = (ContractFragment) cjk.ˎ().ˊ(new cjm("familyshareapp.all.fragment", appTracesListFragmentProtocol));
                    if (this.ॱ.ˊˋ == null) {
                        this.ॱ.ˊˋ = new ContractFragment();
                    }
                    return this.ॱ.ˊˋ;
                case 1:
                    request = new Request();
                    request.ॱ(1);
                    request.ʽ(true);
                    appTracesListFragmentProtocol.ˏ(request);
                    request.ॱˊ(this.ॱ.ॱˊ);
                    this.ॱ.ˊˊ = (ContractFragment) cjk.ˎ().ˊ(new cjm("familyshareapp.uninstall.fragment", appTracesListFragmentProtocol));
                    if (this.ॱ.ˊˊ == null) {
                        this.ॱ.ˊˊ = new ContractFragment();
                    }
                    return this.ॱ.ˊˊ;
                default:
                    return new ContractFragment();
            }
        }

        public int getCount() {
            return this.ॱ.ˈ.ॱ();
        }

        public void setPrimaryItem(ViewGroup viewGroup, int i, Object obj) {
            super.setPrimaryItem(viewGroup, i, obj);
            Fragment fragment = (Fragment) obj;
            if (fragment != this.ˎ) {
                this.ˎ = fragment;
                this.ॱ.ˊˋ();
            }
        }

        Fragment ॱ() {
            return this.ˎ;
        }
    }

    public void ˎ(ctn o_ctn) {
        this.ॱˎ.add(o_ctn);
    }

    public void ˊ(ctn o_ctn) {
        this.ॱˎ.remove(o_ctn);
    }

    public void ˊ(a aVar, FragmentTransaction kaVar) {
        if (this.mFixViewPager != null) {
            c cVar = (c) this.mFixViewPager.getAdapter();
            if (cVar != null) {
                Fragment ॱ = cVar.ॱ();
                if (ॱ instanceof ciy) {
                    ((ciy) ॱ).ʾॱ();
                }
            }
        }
    }

    public void ˎ(a aVar, FragmentTransaction kaVar) {
        if (this.ˈ != null) {
            int ˊ = this.ˈ.ˊ();
            if (this.mFixViewPager != null) {
                this.mFixViewPager.setCurrentItem(ˊ);
            }
        }
    }

    public void ॱ(a aVar, FragmentTransaction kaVar) {
    }

    protected int ᐝ() {
        return f.ˋ;
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        int itemId = menuItem.getItemId();
        if (itemId == 16908332) {
            finish();
            return true;
        } else if (itemId != e.ʽ) {
            return super.onOptionsItemSelected(menuItem);
        } else {
            ˎˎ();
            return true;
        }
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(d.ˏ);
        getWindow().getDecorView().setBackgroundColor(getResources().getColor(cst.a.ʼ));
        cgv.ˋ(this, cst.a.ॱ, cst.a.ˊ);
        PurchaseHistoryProtocol purchaseHistoryProtocol = (PurchaseHistoryProtocol) ʾ();
        if (purchaseHistoryProtocol == null || purchaseHistoryProtocol.ˏ() == null) {
            csp.ˏ.ˏ("PurchaseFamilyShareAppsActivity", "invalid protocol, finish");
            return;
        }
        this.ॱˊ = purchaseHistoryProtocol.ˏ().ˏ();
        this.ʿ = purchaseHistoryProtocol.ˏ().ˊ();
        this.ॱˊ = purchaseHistoryProtocol.ˏ().ˏ();
        ˊᐝ();
        ˋˋ();
        ˋˊ();
    }

    private void ˊᐝ() {
        View findViewById = findViewById(e.ᐝᐝ);
        azb.ˏ(findViewById);
        this.ʻॱ = findViewById.findViewById(e.ॱʻ);
        ॱ(findViewById);
        ((LinearLayout) findViewById.findViewById(e.ͺ)).setOnClickListener(this);
        ActionBar actionBar = getActionBar();
        if (azc.ˎ().ॱ() < 21) {
            ((TextView) findViewById.findViewById(e.ᐝˋ)).setText(this.ʿ);
            if (actionBar != null) {
                actionBar.hide();
            }
        } else if (actionBar != null) {
            actionBar.show();
            actionBar.setTitle(this.ʿ);
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayOptions(12);
            findViewById.setVisibility(8);
        }
    }

    private void ॱ(View view) {
        view.findViewById(e.ᐧ).setOnClickListener(new evx(this) {
            final /* synthetic */ PurchaseFamilyShareAppsActivity ˎ;

            {
                this.ˎ = r1;
            }

            public void ˋ(View view) {
                this.ˎ.onBackPressed();
            }
        });
    }

    private void ˋˊ() {
        this.mFixViewPager = (FixViewPager) findViewById(e.ـ);
        this.ˈ = (HwSubTabWidget) findViewById(e.ˊˋ);
        ˍ();
        this.mFixViewPager.setOnPageChangeListener(new cti(this.ˈ, this));
        this.mFixViewPager.setAdapter(new c(this, ˏॱ()));
        this.mFixViewPager.setCurrentItem(this.ˋˊ);
        ͺ();
        ˊ(false);
    }

    protected void ͺ() {
        int ˊ = epv.ˊ(this, 1);
        LayoutParams layoutParams = (LayoutParams) this.ˋॱ.getLayoutParams();
        layoutParams.gravity = 17;
        layoutParams.width = ˊ;
        this.ˋॱ.setLayoutParams(layoutParams);
    }

    public void onClick(View view) {
        int id = view.getId();
        if (id == e.ʽ || id == e.ͺ) {
            ˎˎ();
        }
    }

    private void ˎˎ() {
        if (this.mFixViewPager != null) {
            int ˋ = this.mFixViewPager.getCurrentItem();
            ContractFragment contractFragment = null;
            if (ˋ == 0) {
                contractFragment = this.ˊˋ;
            } else if (ˋ == 1) {
                contractFragment = this.ˊˊ;
            }
            if (contractFragment instanceof ctp) {
                ((ctp) contractFragment).ٴ();
            } else {
                csp.ˏ.ˏ("PurchaseFamilyShareAppsActivity", "fragment not instanceof PurchaseJumper");
            }
        }
    }

    public void ˎ(int i) {
        if (i == 0) {
            ˋ(this.ˊˋ);
        } else if (i == 1) {
            ˋ(this.ˊˊ);
        } else {
            ˊ(false);
        }
    }

    private void ˍ() {
        String[] ॱˊ = ॱˊ();
        this.ˈ.ˎ();
        if (this.ˋˊ < 0 || this.ˋˊ >= ॱˊ.length) {
            this.ˋˊ = 0;
        }
        int length = ॱˊ.length;
        for (int i = 0; i < length; i++) {
            boolean z;
            HwSubTabWidget hwSubTabWidget = this.ˈ;
            hwSubTabWidget.getClass();
            a aVar = new a(hwSubTabWidget, ॱˊ[i], this);
            aVar.ˎ(i);
            HwSubTabWidget hwSubTabWidget2 = this.ˈ;
            if (i == this.ˋˊ) {
                z = true;
            } else {
                z = false;
            }
            hwSubTabWidget2.ॱ(aVar, z);
        }
    }

    private void ˋˋ() {
        this.ᐝॱ = findViewById(e.ˋॱ);
        this.ˋॱ = (ToolBarIcon) findViewById(e.ʽ);
        this.ˋॱ.setOnClickListener(this);
    }

    protected String[] ॱˊ() {
        this.ˏॱ = ContentManager.getInstant().getContext().getResources().getString(h.ˈ);
        this.ͺ = ContentManager.getInstant().getContext().getResources().getString(h.ʿ);
        return new String[]{this.ˏॱ, this.ͺ};
    }

    public void onDestroy() {
        super.onDestroy();
        ˌ();
    }

    private void ˌ() {
        for (String ˊ : csv.ˋ().ʻ()) {
            PurchaseHistoryManager.getHelper().ˊ(ˊ);
        }
    }

    protected void ah_() {
    }

    protected void ᐝॱ() {
        ˏ(false, (LinearLayout) this.ʻॱ.findViewById(e.ͺ));
    }

    protected void ʼॱ() {
        ˏ(true, (ToolBarIcon) this.ᐝॱ.findViewById(e.ʽ));
    }

    private void ˏ(boolean z, View... viewArr) {
        if (z) {
            this.ᐝॱ.setVisibility(this.ˊॱ ? 0 : 8);
        } else {
            this.ʻॱ.setVisibility(this.ˊॱ ? 0 : 8);
        }
        cgv.ˋ(this, cst.a.ॱ, this.ˊॱ ? cst.a.ˊ : cst.a.ʼ);
        int length = viewArr.length;
        for (int i = 0; i < length; i++) {
            if (i == length - 1) {
                int i2;
                View view = viewArr[i];
                if (this.ˊॱ) {
                    i2 = 0;
                } else {
                    i2 = 8;
                }
                view.setVisibility(i2);
                viewArr[i].setEnabled(this.ˊॱ);
            } else {
                viewArr[i].setEnabled(false);
                viewArr[i].setVisibility(8);
            }
        }
    }

    public void ॱ(boolean z) {
        this.ˊॱ = z;
    }

    public void ˉ() {
        int ˋ = this.mFixViewPager.getCurrentItem();
        if (ˋ == 1) {
            ((FamilyShareAppsFragment) this.ˊˋ).ॱʾ();
        } else if (ˋ == 0) {
            ((FamilyShareAppsFragment) this.ˊˊ).ॱʾ();
        }
    }
}
